"use strict";
cc._RF.push(module, '25e15JfsyVLn6Swh2POCg11', 'Dispatcher');
// scripts/Dispatcher.ts

Object.defineProperty(exports, "__esModule", { value: true });
var Dispatcher = /** @class */ (function () {
    function Dispatcher() {
        this.dict = new Object();
    }
    //添加一个回调函数
    Dispatcher.prototype.add = function (type, callback, thisObj) {
        var callbacks = this.dict[type];
        if (callbacks) {
            if (this.getIndex(callbacks, callback, thisObj) != -1)
                return;
        }
        else {
            callbacks = new Array();
            this.dict[type] = callbacks;
        }
        callbacks.push({ 'callback': callback, 'thisObj': thisObj });
    };
    Dispatcher.prototype.getIndex = function (array, callback, thisObj) {
        for (var i = 0; i < array.length; i++) {
            var data = array[i];
            if (data['callback'] == callback && data['thisObj'] == thisObj) {
                return i;
            }
        }
        return -1;
    };
    //删除一个回调函数
    Dispatcher.prototype.remove = function (type, callback, thisObj) {
        //没有该类型的数组
        if (!this.dict[type]) {
            return;
        }
        var callbacks = this.dict[type];
        if (!callbacks) {
            return;
        }
        var index = this.getIndex(callbacks, callback, thisObj);
        if (index != -1) {
            callbacks.splice(index, 1);
        }
        if (callbacks.length <= 0) {
            delete this.dict[type];
        }
    };
    //执行回调
    Dispatcher.prototype.execute = function (type, params) {
        if (params === void 0) { params = null; }
        var callbacks = this.dict[type];
        if (callbacks == undefined)
            return;
        for (var i = 0; i < callbacks.length; i++) {
            var data = callbacks[i];
            var callback = data['callback'];
            var thisObj = data['thisObj'];
            callback.apply(thisObj, [params]);
        }
    };
    return Dispatcher;
}());
exports.default = Dispatcher;

cc._RF.pop();